package leetcode;

import java.util.HashMap;
import java.util.Map;


public class TwoSum {
	public int[] twoSum(int[] nums, int target) {

		Map<Integer, Integer> m = new HashMap<>(nums.length);

		int[] index = new int[2];
		for (int i = 0; i < nums.length; i++) {
			int another = target - nums[i];
			if (m.containsKey(another)) {
				index[0] = m.get(another);
				index[1] = i;
				break;
			}else{
				m.put(nums[i], i);
			}
		}
		return index;

	}
}
